package com.totoro.service.impl;

import com.totoro.mapper.AddressMapper;
import com.totoro.pojo.Address;
import com.totoro.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

/**
 * @author TOTORO
 * @date 2021/7/2 9:47
 */
@Service
public class AddressServiceImpl implements AddressService {
    @Autowired
    AddressMapper addressMapper;

    @Override
    public List<Address> findAddressByUid(int uid) {
        List<Address> list = addressMapper.findAddressByUid(uid);
        list.sort(Comparator.comparing(Address::getDefaultAddress).reversed());
        return list;
    }

    @Override
    public int addAddress(Address address) {
        return addressMapper.addAddress(address);
    }

    @Override
    public Address findAddressByAid(int aid) {
        return addressMapper.findAddressByAid(aid);
    }

    @Override
    public int updateAddressNotDefaultByUidAndAid(int uid, int aid) {
        return addressMapper.updateAddressNotDefaultByUidAndAid(uid, aid);
    }

    @Override
    public int updateAddressIsDefaultByAid(int aid) {
        return addressMapper.updateAddressIsDefaultByAid(aid);
    }

    @Override
    public Integer getAddressLength() {
        return addressMapper.getAddressLength();
    }

    @Override
    public Integer updateAddressByAid(Address address) {
        return addressMapper.updateAddressByAid(address);
    }

    @Override
    public Integer deleteAddress(int aid) {
        return addressMapper.deleteAddress(aid);
    }
}
